package com.tendory.jt808.msg;

import com.tendory.jt808.util.ArrayUtils;
import com.tendory.jt808.util.IntegerUtils;
import com.tendory.jt808.util.LogUtils;

public class ServerGenericRequest extends Message {

    private static final String TAG = LogUtils.makeTag(ServerGenericRequest.class);

    public static final short ID = 0x0001;

    private final short flowId;     //WORD
    private final short replyId;    //WORD
    private final byte resultCode; //BYTE

    private ServerGenericRequest(Builder builder) {
        super(ID, builder.cipher, builder.phone, builder.body);

        flowId = builder.flowId;
        replyId = builder.replyId;
        resultCode = builder.resultCode;
    }

    public static class Builder extends MessageBuilder {

        // Optional parameters - initialized to default values
        private short flowId = 0;
        private short replyId = 0;
        private byte resultCode = 0;

        public Builder flowId(short id) {
            this.flowId = id;
            return this;
        }

        public Builder replyId(short id) {
            this.replyId = id;
            return this;
        }

        public Builder resultCode(byte id) {
            this.resultCode = id;
            return this;
        }


        @Override
        public ServerGenericRequest build() {
            this.body = ArrayUtils.concatenate(IntegerUtils.asBytes(this.flowId),
                    IntegerUtils.asBytes(this.replyId),
                    IntegerUtils.asBytes(this.resultCode));

            return new ServerGenericRequest(this);
        }

    }

}
